package com.yanjiali.controller;

import com.yanjiali.model.R;
import com.yanjiali.model.req.*;
import com.yanjiali.model.resp.*;
import com.yanjiali.service.CommentLikeService;
import com.yanjiali.service.CommentService;
import com.yanjiali.feign.CommentServiceFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import com.yanjiali.model.GetLikeCommentListResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Package: com.yanjiali.controller
 * @Author: yanjiali
 * @Created: 2025/4/23 21:35
 * TODO 显然所有返回的评论视图里面都需要包括对应的用户基本信息，而一级评论中还要包含二级评论
 */
@RestController
@Api("评论控制器")
@RequestMapping("/v1/comments")
public class CommentController implements CommentServiceFeign {

    @Autowired
    private CommentService commentService;

    @Autowired
    private CommentLikeService commentLikeService;

    @PostMapping("/page")
    @ApiOperation("根据文章id分页查询评论列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageGetCommentListByArticleIdReq", value = "分页获取评论列表通过对应文章id请求参数")
    })
    public R<PageGetCommentListByArticleIdResp> queryTheCommentListByPageAccordingToTheArticleId(@RequestBody PageGetCommentListByArticleIdReq pageGetCommentListByArticleIdReq) {
        return commentService
                .queryTheCommentListByPageAccordingToTheArticleId(pageGetCommentListByArticleIdReq);
    }

    @PostMapping("/replyPage")
    @ApiOperation("根据parentId分页查询回复")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageGetReplyByParentIdReq", value = "分页查询对应评论的回复评论，通过parentId")
    })
    public R<PageGetReplyByParentIdResp> pageGetReplyByParentId(@RequestBody PageGetReplyByParentIdReq pageGetReplyByParentIdReq) {
        return commentService.pageGetReplyByParentId(pageGetReplyByParentIdReq);
    }

    @PostMapping("/save")
    @ApiOperation("添加评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "addCommentReq", value = "添加评论请求参数")
    })
    public R<AddCommentResp> addComment(@RequestBody AddCommentReq addCommentReq) {
        return commentService.addComment(addCommentReq);
    }

    @PostMapping("/delete")
    @ApiOperation("删除评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deleteCommentReq", value = "删除评论请求参数")
    })
    public R<DeleteCommentResp> deleteComment(@RequestBody DeleteCommentReq deleteCommentReq) {
        return commentService.deleteComment(deleteCommentReq);
    }

    @PostMapping("/liked")
    @ApiOperation("评论点赞或取消点赞")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentLikesReq", value = "评论点赞或取消点赞请求参数")
    })
    public R<CommentLikesResp> liked(@RequestBody CommentLikesReq commentLikesReq) {
        return commentLikeService.liked(commentLikesReq);
    }


    @Override
    public R<GetLikeCommentListResp> getLikeCommentList() {
        return commentService.getLikeCommentList();
    }
}